//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.member;

import com.aidong.dao.base.ConditionMap;
import com.aidong.dao.base.OrderSet;
import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.CardTypeCodeDao;
import com.aidong.dao.wills.MemberEarnestDao;
import com.aidong.model.wills.CardTypeCode;
import com.aidong.model.wills.MemberEarnest;
import com.aidong.model.wills.MemberInfo;
import com.aidong.model.wills.PayList;
import com.aidong.util.ExportXls;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"memberEarnest"})
public class MemberEarnestController extends PayController {
    @Resource
    MemberEarnestDao memberEarnestDao;
    @Resource
    CardTypeCodeDao cardTypeCodeDao;

    public MemberEarnestController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        return (new ModelAndView("member/earnest/list")).addObject("shopName", this.getTypeList("shopName")).addObject("earnestType", this.getTypeList("earnestType")).addObject("earnestStatus", this.getTypeList("earnestStatus"));
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "shopCode", required = false) String shopCode, @RequestParam(value = "earnestType", required = false) String earnestType, @RequestParam(value = "dateType", required = false) String dateType, @RequestParam(value = "dateFrom", required = false) String dateFrom, @RequestParam(value = "dateTo", required = false) String dateTo, @RequestParam(value = "saleId", required = false) String saleId, @RequestParam(value = "cardCode", required = false) String cardCode, @RequestParam(value = "custName", required = false) String custName, @RequestParam(value = "status", required = false) Integer status, @RequestParam(value = "pageNo", required = false) String pageNo, @RequestParam(value = "totalCount", required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ConditionMap cd = new ConditionMap();
        this.addConditionShopCode(cd, "shopCode", shopCode);
        cd.eq("earnestType", earnestType);
        cd.eq("saleId", this.parseInt(saleId));
        if ("2".equals(dateType)) {
            if (!this.chkNull(dateFrom)) {
                cd.ge("useDate", this.getDateFrom(dateFrom));
            }

            if (!this.chkNull(dateTo)) {
                cd.le("useDate", this.getDateTo(dateTo));
            }
        } else {
            if (!this.chkNull(dateFrom)) {
                cd.ge("saleDate", this.getDateFrom(dateFrom));
            }

            if (!this.chkNull(dateTo)) {
                cd.le("saleDate", this.getDateTo(dateTo));
            }
        }

        cd.eq("cardCode", cardCode);
        if (!this.chkNull(custName)) {
            cd.like("custName", "%" + custName + "%");
        }

        cd.eq("status", status);
        this.memberEarnestDao.queryPageList(pg, cd, (new OrderSet()).desc("saleDate"));
        ModelAndView mv = new ModelAndView("member/earnest/_list");
        mv.addObject("list", pg.getResultList());
        mv.addObject("pg", pg);
        return mv;
    }

    @RequestMapping({"expt"})
    public ModelAndView expt(@RequestParam(value = "shopCode", required = false) String shopCode, @RequestParam(value = "earnestType", required = false) String earnestType, @RequestParam(value = "dateFrom", required = false) String dateFrom, @RequestParam(value = "dateTo", required = false) String dateTo, @RequestParam(value = "cardCode", required = false) String cardCode, @RequestParam(value = "custName", required = false) String custName, @RequestParam(value = "status", required = false) Integer status, HttpServletResponse response) {
        try {
            Pagination e = new Pagination(1, '\uea60');
            e.setPage(Integer.valueOf(1), Integer.valueOf(1));
            ConditionMap cd = new ConditionMap();
            this.addConditionShopCode(cd, "shopCode", shopCode);
            cd.eq("earnestType", earnestType);
            if (!this.chkNull(dateFrom)) {
                cd.ge("saleDate", this.getDateFrom(dateFrom));
            }

            if (!this.chkNull(dateTo)) {
                cd.le("saleDate", this.getDateTo(dateTo));
            }

            cd.eq("cardCode", cardCode);
            if (!this.chkNull(custName)) {
                cd.like("custName", "%" + custName + "%");
            }

            cd.eq("status", status);
            this.memberEarnestDao.queryPageList(e, cd, (new OrderSet()).desc("saleDate"));
            ExportXls xls = new ExportXls(response, "定金销售流水", "定金销售流水");
            xls.addHead(new String[]{"门店编号", "门店名称", "定金编号", "销售日期", "会员姓名", "会员号", "卡号", "定金金额", "收款金额", "全额定金", "状态", "定金类型", "使用日期", "(退/合并)日期", "销售员", "销售员2", "操作员", "备注", "卡种编号", "卡种名称", "卡价"});
            xls.setWidth(new int[]{10, 10, 10, 20, 10, 20, 10, 10, 10, 10, 10, 10, 20, 20, 15, 15, 15, 20, 10, 20, 10});
            new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Iterator i$ = e.getResultList().iterator();

            while (i$.hasNext()) {
                MemberEarnest earnest = (MemberEarnest) i$.next();
                xls.addRow(new Object[]{earnest.getShopCode(), this.cache.getValue("shopName", earnest.getShopCode()), earnest.getSaleId(), sdf2.format(earnest.getSaleDate()), earnest.getCustName(), earnest.getMemberCode(), earnest.getCardCode(), earnest.getEarnestAmount(), earnest.getPayAmount(), this.chkNullZ(earnest.getAmountFull()) ? "否" : "是", this.cache.getValue("earnestStatus", String.valueOf(earnest.getStatus())), this.cache.getValue("earnestType", earnest.getEarnestType()), earnest.getUseDate() != null ? sdf2.format(earnest.getUseDate()) : "", earnest.getCancelDate() != null ? sdf2.format(earnest.getCancelDate()) : "", this.nvl(earnest.getSalesCode()) + " - " + this.nvl(this.cache.getValue("salesName", earnest.getSalesCode())), this.nvl(earnest.getSalesCode2()) + " - " + this.nvl(this.cache.getValue("salesName", earnest.getSalesCode2())), this.nvl(earnest.getCreateUser()) + " - " + this.nvl(this.cache.getValue("userName", earnest.getCreateUser())), earnest.getNote(), earnest.getCardType(), this.cache.getValue("cardType", earnest.getCardType()), earnest.getCardPrice()});
            }

            xls.close();
            this.addUserLog("导出会籍销售流水", e.getResultList().size() + "条记录");
        } catch (Exception var16) {
            this.log.error("import", var16);
        }

        return null;
    }

    @RequestMapping({"add"})
    public ModelAndView add(@RequestParam(value = "earnType", required = false) String earnType) {
        List promotionList = this.promotionDao.getShopPromotionList(this.getLoginShopCode());
        List list = this.cardTypeCodeDao.getShopCardTypeList(this.getLoginShopCode(), 1, 0);
        ModelAndView mv = new ModelAndView("member/earnest/add");
        mv.addObject("promotionList", promotionList);
        mv.addObject("cardTypeList", list);
        mv.addObject("gender", this.getTypeList("gender"));
        mv.addObject("idType", this.getTypeList("idType"));
        mv.addObject("earnestType", this.getTypeList("earnestType"));
        mv.addObject("earnType", earnType);
        mv.addObject("_oper", "add");
        return mv;
    }

    @RequestMapping({"_add"})
    @ResponseBody
    public String _add(@ModelAttribute("earnest") MemberEarnest earnest, @RequestParam("payls") String payls) {
        MemberInfo sdf;
        if ("2".equals(earnest.getMemberType())) {
            if (this.chkNull(earnest.getCardCode())) {
                return this.getResult(false, "请输入会员卡号");
            }

            sdf = this.memberInfoDao.getByCardCode(earnest.getCardCode());
            if (sdf == null) {
                return this.getResult(false, "会员卡号错误");
            }

            if (this.memberBlackListDao.chkExists(sdf.getIdType(), sdf.getIdNumber())) {
                return this.getFail(-8, "证件号在黑名单中，不能办理定金");
            }

            earnest.setCardCode(sdf.getCardCode());
            earnest.setMemberCode(sdf.getMemberCode());
            earnest.setCustName(sdf.getChName());
            earnest.setGender(sdf.getGender());
            earnest.setIdType(sdf.getIdType());
            earnest.setIdNumber(sdf.getIdNumber());
        } else {
            if (this.chkNull(earnest.getCustName())) {
                return this.getResult(false, "请输入会员姓名");
            }

            if (this.chkNull(earnest.getMobile())) {
                return this.getResult(false, "请输入手机号");
            }

            if (earnest.getIdType() == null) {
                earnest.setIdType("");
            }

            if (earnest.getIdNumber() == null) {
                earnest.setIdNumber("");
            }

            sdf = null;
            if (!this.chkNull(earnest.getIdType()) && !this.chkNull(earnest.getIdNumber())) {
                if (this.memberBlackListDao.chkExists(earnest.getIdType(), earnest.getIdNumber())) {
                    return this.getFail(-8, "证件号在黑名单中，不能办理定金");
                }

                sdf = this.memberInfoDao.getByIdNumber(earnest.getIdType(), earnest.getIdNumber());
            }

            if (sdf != null) {
                earnest.setCardCode(sdf.getCardCode());
                earnest.setMemberCode(sdf.getMemberCode());
                earnest.setCustName(sdf.getChName());
            } else {
                earnest.setCardCode((String) null);
                earnest.setMemberCode((String) null);
            }
        }

        earnest.setAmountFull(Integer.valueOf(0));
        if ("1".equals(earnest.getEarnestType()) && !this.chkNull(earnest.getCardType())) {
            CardTypeCode sdf1 = (CardTypeCode) this.cardTypeCodeDao.getById(earnest.getCardType());
            if (sdf1 == null) {
                return this.getResult(false, "没有这个卡种");
            }
            Double discount = this.cardTypeCodeDao.getCardTypeDiscount(earnest.getCardType(), this.getLoginShopCode());
            if (sdf1 == null) {
                return this.getResult(false, "不能在本店销售");
            }
            earnest.setCardPrice(discount * sdf1.getPrice());
            earnest.setAmountFull(Integer.valueOf(this.equals(earnest.getPayAmount().doubleValue(), discount * sdf1.getPrice()) ? 1 : 0));
        }

        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdf11 = new SimpleDateFormat("yyyy-MM");
        Calendar cal = Calendar.getInstance();
        cal.add(2, 2);
        earnest.setShopCode(this.getLoginShopCode());
        earnest.setSaleDate(new Date());
        earnest.setEarnestAmount(earnest.getPayAmount());
        earnest.setStatus(Integer.valueOf(0));
        earnest.setOverDueUse(Integer.valueOf(0));
        earnest.setEarnestMerge(Integer.valueOf(0));
        earnest.setEarnestDelay(Integer.valueOf(0));
        earnest.setSignStatus(Integer.valueOf(this.chkNullZ(earnest.getSignStatus()) ? 2 : 0));
        earnest.setPrintLabel(Integer.valueOf(0));
        earnest.setCreateUser(this.getLoginUserCode());
        earnest.setCreateTime(new Date());
        earnest.setUpdateTime(new Date());
        ArrayList payList = new ArrayList();
        StringBuilder payMsg = new StringBuilder();
        PayList pay = this.getPayList(payls, payList, "08", payMsg);
        if (pay == null) {
            return this.getResult(false, payMsg.toString());
        } else if (!this.equals(pay.getAmount().doubleValue(), earnest.getPayAmount().doubleValue())) {
            return this.getResult(false, "付款金额不一致");
        } else {
            earnest.setSalesCode(pay.getSalesCode());
            earnest.setSalesCode2(pay.getSalesCode2());

            try {
                earnest.setOverDueDate(sdf2.parse(sdf11.format(cal.getTime()) + "-01"));
                this.memberEarnestDao.addEarnest(earnest, payList);
                this.smsListService.addSmsList("1".equals(earnest.getEarnestType()) ? "41" : "42", earnest.getSaleId().intValue());
                this.addUserLog("新增定金", "编号:" + earnest.getSaleId() + ",姓名:" + earnest.getCustName());
            } catch (Exception var10) {
                this.log.error("add earnest", var10);
                return this.getResult(false, "保存发生错误");
            }

            return this.getSuccess(String.valueOf(earnest.getSaleId()), "保存完成");
        }
    }

    @RequestMapping({"getIdNumberMember"})
    @ResponseBody
    public String getIdNumberMember(@RequestParam("idt") String idType, @RequestParam("idn") String idNumber) {
        if (this.memberBlackListDao.chkExists(idType, idNumber)) {
            return this.getFail(-8, "证件号在黑名单中，不能办理定金");
        } else {
            MemberInfo member = this.memberInfoDao.getByIdNumber(idType, idNumber);
            if (member == null) {
                return this.getResult(false, "没有会员信息");
            } else {
                StringBuilder sb = new StringBuilder();
                sb.append("{code:\"").append(member.getMemberCode()).append("\"").append(",card:\"").append(member.getCardCode()).append("\"").append(",shop:\"").append(member.getShopCode()).append("\"").append(",name:\"").append(member.getChName()).append("\"").append(",gender:\"").append(member.getGender()).append("\"").append(",idType:\"").append(member.getIdType()).append("\"").append(",idNumber:\"").append(member.getIdNumber()).append("\"").append(",mobile:\"").append(member.getMobile()).append("\"").append("}");
                return this.getSuccess(sb.toString(), "");
            }
        }
    }

    @RequestMapping({"merge"})
    public ModelAndView merge(@RequestParam(value = "earnType", required = false) String earnType, @RequestParam(value = "ids", required = false) String ids) {
        List promotionList = this.promotionDao.getShopPromotionList(this.getLoginShopCode());
        List list = this.cardTypeCodeDao.getShopCardTypeList(this.getLoginShopCode(), 1, 0);
        ArrayList earnestList = new ArrayList();
        double totalMoney = 0.0D;
        if (!this.chkNull(ids)) {
            String[] mv = ids.split(",");
            String[] arr$ = mv;
            int len$ = mv.length;

            for (int i$ = 0; i$ < len$; ++i$) {
                String id = arr$[i$];
                Integer sid = this.parseInt(id);
                if (this.chkNullZ(sid)) {
                    return this.showAlert(" 定金号错误:" + id);
                }

                MemberEarnest earnest1 = (MemberEarnest) this.memberEarnestDao.getById(sid);
                if (earnest1 == null || earnest1.getStatus().intValue() != 0) {
                    return this.showAlert("没有这个定金:" + id);
                }

                earnestList.add(earnest1);
                totalMoney += earnest1.getEarnestAmount().doubleValue();
            }
        }

        ModelAndView var15 = new ModelAndView("member/earnest/merge");
        var15.addObject("ids", ids);
        var15.addObject("earnestList", earnestList);
        var15.addObject("totalMoney", Double.valueOf(totalMoney));
        var15.addObject("promotionList", promotionList);
        var15.addObject("cardTypeList", list);
        var15.addObject("gender", this.getTypeList("gender"));
        var15.addObject("idType", this.getTypeList("idType"));
        var15.addObject("earnestType", this.getTypeList("earnestType"));
        var15.addObject("earnType", earnType);
        var15.addObject("_oper", "add");
        return var15;
    }

    @RequestMapping({"_merge"})
    @ResponseBody
    public String _merge(@ModelAttribute("earnest") MemberEarnest earnest, @RequestParam("ids") String ids) {
        ArrayList oldList = new ArrayList();
        double totalMoney = 0.0D;
        byte delay = 0;
        String[] idss = ids.split(",");
        String[] sdf = idss;
        int sdf1 = idss.length;
        int cal = 0;

        while (true) {
            MemberEarnest earnest1;
            if (cal < sdf1) {
                String var21 = sdf[cal];
                Integer var22 = this.parseInt(var21);
                if (this.chkNullZ(var22)) {
                    return this.getResult(false, " 定金号错误:" + var21);
                }

                earnest1 = (MemberEarnest) this.memberEarnestDao.getById(var22);
                if (earnest1 != null && earnest1.getStatus().intValue() == 0) {
                    oldList.add(earnest1);
                    totalMoney += earnest1.getEarnestAmount().doubleValue();
                    if (!this.chkNullZ(earnest1.getEarnestDelay())) {
                        delay = 1;
                    } else if (earnest1.getOverDueDate() != null && earnest1.getOverDueDate().getTime() < System.currentTimeMillis()) {
                        delay = 1;
                    }

                    ++cal;
                    continue;
                }

                return this.getResult(false, " 没有这个定金:" + var21);
            }

            if (!this.equals(earnest.getPayAmount().doubleValue(), totalMoney)) {
                return this.getResult(false, "付款金额不一致");
            }

            earnest.setEarnestAmount(earnest.getPayAmount());
            earnest.setPayAmount(Double.valueOf(0.0D));
            MemberInfo var15;
            if ("2".equals(earnest.getMemberType())) {
                if (this.chkNull(earnest.getCardCode())) {
                    return this.getResult(false, "请输入会员卡号");
                }

                var15 = this.memberInfoDao.getByCardCode(earnest.getCardCode());
                if (var15 == null) {
                    return this.getResult(false, "会员卡号错误");
                }

                earnest.setCardCode(var15.getCardCode());
                earnest.setMemberCode(var15.getMemberCode());
                earnest.setCustName(var15.getChName());
                earnest.setGender(var15.getGender());
                earnest.setIdType(var15.getIdType());
                earnest.setIdNumber(var15.getIdNumber());
            } else {
                if (this.chkNull(earnest.getCustName())) {
                    return this.getResult(false, "请输入会员姓名");
                }

                if (this.chkNull(earnest.getIdType())) {
                    return this.getResult(false, "请输入证件类型");
                }

                if (this.chkNull(earnest.getIdNumber())) {
                    return this.getResult(false, "请输入证件号");
                }

                if (this.chkNull(earnest.getMobile())) {
                    return this.getResult(false, "请输入手机号");
                }

                var15 = this.memberInfoDao.getByIdNumber(earnest.getIdType(), earnest.getIdNumber());
                if (var15 != null) {
                    earnest.setCardCode(var15.getCardCode());
                    earnest.setMemberCode(var15.getMemberCode());
                    earnest.setCustName(var15.getChName());
                } else {
                    earnest.setCardCode((String) null);
                    earnest.setMemberCode((String) null);
                }
            }

            earnest.setAmountFull(Integer.valueOf(0));
            if ("1".equals(earnest.getEarnestType()) && !this.chkNull(earnest.getCardType())) {
                CardTypeCode var16 = (CardTypeCode) this.cardTypeCodeDao.getById(earnest.getCardType());
                if (var16 == null) {
                    return this.getResult(false, "没有这个卡种");
                }

                Double var18 = this.cardTypeCodeDao.getCardTypeDiscount(earnest.getCardType(), this.getLoginShopCode());
                if (var18 == null) {
                    return this.getResult(false, "不能在本店销售");
                }

                earnest.setCardPrice(Double.valueOf(var16.getPrice().doubleValue() * var18.doubleValue()));
                earnest.setAmountFull(Integer.valueOf(0));
            }

            SimpleDateFormat var17 = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat var19 = new SimpleDateFormat("yyyy-MM");
            Calendar var20 = Calendar.getInstance();
            var20.add(2, 2);
            earnest.setShopCode(this.getLoginShopCode());
            earnest.setSaleDate(new Date());
            earnest.setStatus(Integer.valueOf(0));
            earnest.setNote("合并定金(" + ids + ")");
            earnest.setOverDueUse(Integer.valueOf(0));
            earnest.setEarnestMerge(Integer.valueOf(1));
            earnest.setEarnestDelay(Integer.valueOf(delay));
            earnest.setSignStatus(Integer.valueOf(0));
            earnest.setPrintLabel(Integer.valueOf(0));
            earnest.setCreateUser(this.getLoginUserCode());
            earnest.setCreateTime(new Date());
            earnest.setUpdateTime(new Date());
            earnest.setSalesCode("");
            earnest.setSalesCode2("");
            SimpleDateFormat sdf0 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Iterator e = oldList.iterator();

            while (e.hasNext()) {
                earnest1 = (MemberEarnest) e.next();
                earnest1.setStatus(Integer.valueOf(4));
                earnest1.setNote(this.nvl(earnest1.getNote()) + "(该定金已合并,合并时间:" + sdf0.format(new Date()) + ")");
                earnest1.setCancelDate(new Date());
                earnest1.setCancelUser(this.getLoginUserCode());
            }

            try {
                earnest.setOverDueDate(var17.parse(var19.format(var20.getTime()) + "-01"));
                this.memberEarnestDao.addMergeEarnest(earnest, oldList);
                this.addUserLog("合并定金", "编号:" + earnest.getSaleId() + ",姓名:" + earnest.getCustName() + ",原编号:" + ids);
            } catch (Exception var14) {
                this.log.error("merge earnest", var14);
                return this.getResult(false, "保存发生错误");
            }

            return this.getSuccess(String.valueOf(earnest.getSaleId()), "保存完成");
        }
    }

    @RequestMapping({"_back"})
    @ResponseBody
    public String _back(@RequestParam("saleId") int saleId, @RequestParam("payls") String payls) {
        MemberEarnest earnest1 = (MemberEarnest) this.memberEarnestDao.getById(Integer.valueOf(saleId));
        if (earnest1 != null && earnest1.getStatus().intValue() == 0) {
            MemberEarnest earnest = new MemberEarnest();
            earnest.setShopCode(earnest1.getShopCode());
            earnest.setMemberType(earnest1.getMemberType());
            earnest.setMemberCode(earnest1.getMemberCode());
            earnest.setCardCode(earnest1.getCardCode());
            earnest.setCustName(earnest1.getCustName());
            earnest.setGender(earnest1.getGender());
            earnest.setIdType(earnest1.getIdType());
            earnest.setIdNumber(earnest1.getIdNumber());
            earnest.setMobile(earnest1.getMobile());
            earnest.setPhone(earnest1.getPhone());
            earnest.setCardType(earnest1.getCardType());
            earnest.setCardPrice(earnest1.getCardPrice());
            earnest.setAmountFull(Integer.valueOf(0));
            earnest.setEarnestType(earnest1.getEarnestType());
            earnest.setEarnestAmount(Double.valueOf(-earnest1.getEarnestAmount().doubleValue()));
            earnest.setPayAmount(Double.valueOf(-earnest1.getEarnestAmount().doubleValue()));
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM");
            Calendar cal = Calendar.getInstance();
            cal.add(2, 2);
            earnest.setSaleDate(new Date());
            earnest.setStatus(Integer.valueOf(2));
            earnest.setNote("原合同号:" + saleId);
            earnest.setOverDueUse(Integer.valueOf(0));
            earnest.setEarnestMerge(Integer.valueOf(0));
            earnest.setEarnestDelay(Integer.valueOf(0));
            earnest.setSignStatus(Integer.valueOf(0));
            earnest.setPrintLabel(Integer.valueOf(0));
            earnest.setCreateUser(this.getLoginUserCode());
            earnest.setCreateTime(new Date());
            earnest.setUpdateTime(new Date());
            ArrayList payList = new ArrayList();
            StringBuilder payMsg = new StringBuilder();
            PayList pay = this.getPayList(payls, payList, "08", payMsg);
            if (pay == null) {
                return this.getResult(false, payMsg.toString());
            } else if (!this.equals(pay.getAmount().doubleValue(), earnest.getPayAmount().doubleValue())) {
                return this.getResult(false, "付款金额不一致");
            } else {
                earnest.setSalesCode(pay.getSalesCode());
                earnest.setSalesCode2(pay.getSalesCode2());
                SimpleDateFormat sdf0 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                earnest1.setStatus(Integer.valueOf(2));
                earnest1.setNote("(该定金已退款,退款时间:" + sdf0.format(new Date()) + ")");
                earnest1.setCancelDate(new Date());
                earnest1.setCancelUser(this.getLoginUserCode());

                try {
                    earnest.setOverDueDate(sdf.parse(sdf1.format(cal.getTime()) + "-01"));
                    this.memberEarnestDao.addBackEarnest(earnest, earnest1, payList);
                    this.addUserLog("退定金", "退单编号:" + earnest.getSaleId() + ",原编号:" + earnest1.getSaleId());
                } catch (Exception var13) {
                    this.log.error("back earnest", var13);
                    return this.getResult(false, "保存发生错误");
                }

                return this.getSuccess(String.valueOf(earnest.getSaleId()), "保存完成");
            }
        } else {
            return this.getResult(false, " 没有这个定金!");
        }
    }

    @RequestMapping({"getCardTypeList"})
    @ResponseBody
    public String getCardTypeList(@RequestParam("saleType") Integer saleType, @RequestParam("op") String op) {
        int option = 0;
        if (!this.chkNull(op)) {
            if (op.indexOf("r") >= 0) {
                ++option;
            }

            if (op.indexOf("p") >= 0) {
                option += 2;
            }
        }

        List list = this.cardTypeCodeDao.getShopCardTypeList(this.getLoginShopCode(), saleType.intValue(), option);
        DecimalFormat nf = new DecimalFormat("0.##");
        StringBuilder sb = new StringBuilder();
        sb.append("[");

        CardTypeCode cardType;
        for (Iterator i$ = list.iterator(); i$.hasNext(); sb.append("{code:\"").append(cardType.getCode()).append("\"").append(",name:\"").append(cardType.getChName()).append("\"").append(",price:\"").append(cardType.getPrice() == null ? "" : nf.format(cardType.getPrice())).append("\"").append("}")) {
            cardType = (CardTypeCode) i$.next();
            if (sb.length() > 5) {
                sb.append(",");
            }
        }

        sb.append("]");
        return this.getSuccess(sb.toString(), "");
    }
}
